import requests
import http.cookiejar as cookielib

from requests.api import request

class CookieOperator:
    def __init__(self) -> None:
        pass
    
    def save_cookie(cookies, cookie_file_name):
        new_cookie_jar = cookielib.LWPCookieJar(cookie_file_name)
        requests.utils.cookiejar_from_dict(cookies, new_cookie_jar)
        new_cookie_jar.save(cookie_file_name, ignore_discard = True, ignore_expires = True)
    
    def read_cookie(cookie_file_name):
        load_cookie_jar = cookielib.LWPCookieJar()
        load_cookie_jar.load(cookie_file_name, ignore_discard = True, ignore_expires = True)
        cookies = requests.utils.dict_from_cookiejar(load_cookie_jar)
        return cookies
